 <?php 

$listing_id = $_GET['listing_id'];
$group_id = $_GET['group_id'];
//$listing_id = '242801';
//$username='matt';

include("../db/opendb.php");

include("functions.php");

$query = "select i.Path as IMAGE,l.ZIPCODE, l.LONGITUDE, l.LATITUDE, l.IVR, t.Name, l.LANDING_PAGE,  l.VIRTUAL_TOUR_URL, l.YEARBUILT, l.OID, l.STREETNUM, l.STREETNAME, l.STREETSUFFIX, l.UNITFLOORNUM, l.CITY, l.STATE, l.REMARKS from BIZPROPERTIES l inner join Biz_Owner_Con p on p.Prop_OID = l.OID inner join Users u on u.ID = p.Owner left join Biz_Listing_Images i on (i.Listing_ID = l.OID and i.Main_Photo = 1) inner join Biz_Types t on t.ID = l.BIZTYPE where l.OID = '".$listing_id."'";

$result = mysql_query($query) or die ("SQL Error".mysql_error());

$row = mysql_fetch_assoc($result);

$xml = "<listings>\n<listing>\n";
$image = ($row[IMAGE]!='')? 'http://realivent.com/biz_listing_images/resize_'.$row['IMAGE'] :'http://realivent.com/listing_images/no_photo.gif';
$xml .= "\t<main_image>".$image."</main_image>\n";
$xml .= "\t<oid>".$row['OID']."</oid>\n";
$xml .= "\t<streetnum>".$row['STREETNUM']."</streetnum>\n";
$xml .= "\t<streetname>".$row['STREETNAME']."</streetname>\n";
$xml .= "\t<streetsuffix>".$row['STREETSUFFIX']."</streetsuffix>\n";
$xml .= "\t<unit>".$row['UNITFLOORNUM']."</unit>\n";
$xml .= "\t<city>".$row['CITY']."</city>\n";
$xml .= "\t<state>".$row['STATE']."</state>\n";
$xml .= "\t<remarks><![CDATA[".$row['REMARKS']."]]></remarks>\n";
$xml .= "\t<ivr><![CDATA[".$row['IVR']."]]></ivr>\n";
$xml .= "\t<type>".$row['Name']."</type>\n";
$xml .= "\t<yearbuilt>".$row['YEARBUILT']."</yearbuilt>\n";
$xml .= "\t<virtual_tour_url>".$row['VIRTUAL_TOUR_URL']."</virtual_tour_url>\n";
$xml .= "\t<landing_page>".$row['LANDING_PAGE']."</landing_page>\n";
$xml .= "\t<longitude>".$row['LONGITUDE']."</longitude>\n";
$xml .= "\t<latitude>".$row['LATITUDE']."</latitude>\n";
$xml .= "\t<zipcode>".$row['ZIPCODE']."</zipcode>\n";

$xml .= "\t<images>\n";

$query_images = "select * from Biz_Listing_Images where Listing_ID = '".$row['OID']."' and Type = 'IMAGE'";
$result_images = mysql_query($query_images) or die ("SQL Error".mysql_error());
if(mysql_num_rows($result_images))
{
	while($rowi = mysql_fetch_assoc($result_images))
	{
		$xml .= "\t\t<image>http://realivent.com/biz_listing_images/t_".$rowi['Path']."</image>\n";
	}
}
else
{
$xml .= "\t\t<image>http://realivent.com/biz_listing_images/nia_thumb.gif</image>\n";
}

$xml .= "\t</images>\n";

$xml .= "\t<agent>\n";

$query_agent = "select u.* from Users u inner join Biz_Owner_Con c on (c.Owner = u.ID and c.Prop_OID = '".$row['OID']."')";
$result_agent = mysql_query($query_agent) or die ("SQL Error".mysql_error());
$rowa = mysql_fetch_assoc($result_agent);

	$xml .= "\t\t<first_name>".$rowa['First_Name']."</first_name>\n";
	$xml .= "\t\t<last_name>".$rowa['Last_Name']."</last_name>\n";
	$xml .= "\t\t<phone>".$rowa['Phone']."</phone>\n";
	$xml .= "\t\t<email>".$rowa['Email']."</email>\n";
	$xml .= "\t\t<website>".$rowa['Website']."</website>\n";
	$xml .= "\t\t<image>http://realivent.com/user_images/t75_".$rowa['Image']."</image>\n";
	$xml .= "\t\t<logo>http://realivent.com/user_images/t_".$rowa['Company_Logo']."</logo>\n";


$xml .= "\t</agent>\n";



$xml .= "</listing>\n</listings>";
echo $xml;

?>
